package com.igd.socket.sdk.nio;

import java.io.IOException;
import java.io.InputStream;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;
import java.util.Scanner;

public class ReactorNIOSocketClient {
	
	public static void main(String[] args) throws IOException {
		Socket socket = new Socket();
		socket.connect(new InetSocketAddress(10022));
		new Thread(() -> {
			while(true) {
				try {
					InputStream inputStream = socket.getInputStream();
					byte[] data = new byte[1024];
					inputStream.read(data);
					System.out.println("get server：" + new String(data, StandardCharsets.UTF_8));
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}).start();
		while(true) {
			Scanner scanner = new Scanner(System.in);
			while(scanner.hasNextLine()) {
				String s = scanner.nextLine();
				socket.getOutputStream().write(s.getBytes(StandardCharsets.UTF_8));
			}
		}
	}
	

}
